package com.grz.peoxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
public class Main2 {
    public static void main(String[] args) {
        ISinger target = new Cai();
//        ISinger proxy = (ISinger) Proxy.newProxyInstance(target.getClass().getClassLoader(), new Class[]{ISinger.class}, new InvocationHandler() {
//            @Override
//            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//                return null;
//            }
//        });
        ISinger proxy = (ISinger) Proxy.newProxyInstance(target.getClass().getClassLoader(), new Class[]{ISinger.class}, (proxy1, method, args1) -> {
            System.out.println("前置通知...");
            // 方法的调用
            Object result;
            try{
                result = method.invoke(target, args1);
                System.out.println("返回结果...");
            }catch (Throwable e){
                System.out.println("异常通知...");
                throw e;
            }finally {
                // 后置通知
                System.out.println("后置通知");
            }
            return result;
        });
        proxy.jump();
    }
}
